package com.zsk.shop.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.gson.Gson;
import com.zsk.shop.api.order.OrderStatus;
import com.zsk.shop.common.base.BaseResponse;
import com.zsk.shop.common.base.page.BaseDateQueryParams;
import com.zsk.shop.common.base.page.BasePageFactory;
import com.zsk.shop.common.constant.RedisKeys;
import com.zsk.shop.common.utils.*;
import com.zsk.shop.entity.*;
import com.zsk.shop.enums.*;
import com.zsk.shop.mapper.ShopOrderMapper;
import com.zsk.shop.model.params.*;
import com.zsk.shop.model.results.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author Ys
 * @date 2021年12月08日 11:05
 */
@Service
@Slf4j
public class GopOrderService extends ServiceImpl<ShopOrderMapper, ShopOrder> {

    @Resource
    private ShopUserService userService;
    @Resource
    private ShopGoodsService goodsService;
    @Resource
    private ShopGoodsSkuService goodsSkuService;
    @Resource
    private ShopGoodsSkuService shopGoodsSkuService;
    @Resource
    private ShopOrderService shopOrderService;
    @Resource
    private ShopGoodsCategoryService shopGoodsCategoryService;
    @Resource
    private DeliveryAddressStatusService deliveryAddressStatusService;
    @Resource
    private ShopOrderPointsService shopOrderPointsService;

    public List<WaitDeliveryOrderResult> waitDeliveryOrder(String orderStatus, String orderNo, String queryPhone, String goodsName, String startTime, String endTime) {
        LambdaQueryWrapper<ShopOrder> queryWrapper = new LambdaQueryWrapper<>();
        if (ToolUtil.isNotEmpty(orderNo)) {
            queryWrapper.eq(ShopOrder::getOrderNo, orderNo);
        }
        if (ToolUtil.isNotEmpty(orderStatus)) {
            queryWrapper.eq(ShopOrder::getOrderStatus, orderStatus);
        }
        if (ToolUtil.isNotEmpty(queryPhone)) {
            ShopUser user = userService.queryTrueUserByPhone(queryPhone);
            if (ToolUtil.isEmpty(user)) {
                return new ArrayList<>();
            } else {
                queryWrapper.eq(ShopOrder::getUserNo, user.getUserNo());
            }
        }
        if (ToolUtil.isNotEmpty(goodsName)) {
            List<String> goodsNos = new ArrayList<>();
            if (ToolUtil.isEmpty(goodsNos)) {
                return new ArrayList<>();
            } else {
                queryWrapper.in(ShopOrder::getGoodsNo, goodsNos);
            }
        }
        if (!ToolUtil.isAllEmpty(startTime, endTime)) {
            queryWrapper.and(x -> x.ge(ShopOrder::getCreateTime, startTime).le(ShopOrder::getCreateTime, endTime));
        }
        List<ShopOrder> orderList = list(queryWrapper);
        List<WaitDeliveryOrderResult> resultList = EntityConvertUtils.convertAListToBList(orderList, WaitDeliveryOrderResult.class);
        for (WaitDeliveryOrderResult result : resultList) {
            OrderGoodsSnapshotParam snapshotParam = JSON.parseObject(result.getSnapshot(), OrderGoodsSnapshotParam.class);
            result.setGoodsName(snapshotParam.getGoodsName());
            String skuBizNo = snapshotParam.getBizNo();
            ShopGoodsSku shopGoodsSku = goodsSkuService.getGoodsSkuInfo(skuBizNo);
            result.setSkuName(shopGoodsSku.getName());
            result.setImg(shopGoodsSku.getImg());
            result.setName(result.getName());
            result.setPhone(result.getPhone());
            result.setAddressDetail(result.getAddress());
            result.setIsRefund(!result.getRefundStatus().equals(EnumShopOrderRefundStatus.REFUND_NOT.getCode()));
        }
        return resultList;
    }

    public BaseResponse<OrderListResult> getGopOrderList(OrderParam param) {
        List<OrderListResult> results = this.getBaseMapper().queryGopOrderList(param, PageWithSqlUtil.getIndex(param.getPage(), param.getLimit()), PageWithSqlUtil.getSize(param.getPage(), param.getLimit()));
        for (OrderListResult obj : results) {
            if (ToolUtil.isNotEmpty(obj.getSnapshot())) {
                OrderGoodsSnapshotParam goodsSku = new Gson().fromJson(obj.getSnapshot(), OrderGoodsSnapshotParam.class);
                if (ToolUtil.isNotEmpty(goodsSku)) {
                    ShopGoodsCategory category = shopGoodsCategoryService.queryByCategoryNo(goodsSku.getGoodsCategoryNo());
                    if (ToolUtil.isNotEmpty(category)) {
                        obj.setCategoryName(category.getCategoryName());
                    }
                }
            }
            obj.setOrderStatusStr(EnumOrderStatus.getNameByCode(obj.getOrderStatus()));
        }
        return BaseResponse.success("订单列表", results, this.baseMapper.queryGopOrderCount(param));
    }

    public BaseResponse getOrderList(GopOrderParams param) {
        List<GopOrderListResult> results = this.getBaseMapper().getGopOrderList(param, PageWithSqlUtil.getIndex(param.getPage(), param.getLimit()), PageWithSqlUtil.getSize(param.getPage(), param.getLimit()));
        for (GopOrderListResult obj : results) {
            if (ToolUtil.isNotEmpty(obj.getSnapshot())) {
                OrderGoodsSnapshotParam snapshotParam = new Gson().fromJson(obj.getSnapshot(), OrderGoodsSnapshotParam.class);
                if (ToolUtil.isNotEmpty(snapshotParam)) {
                    obj.setGoodsName(snapshotParam.getGoodsName());
                }
            }
            obj.setSnapshot(null);
        }
        return BaseResponse.success("列表数据", results, this.getBaseMapper().getGopOrderCount(param));
    }

    public BaseResponse<OrderInfoResult> getOrderInfo(String orderNo) {
        ShopOrder order = shopOrderService.queryOne(orderNo);
        if (ToolUtil.isNotEmpty(order)) {
            OrderInfoResult result = EntityConvertUtils.convertAToB(order, OrderInfoResult.class);
            DeliveryAddressStatus number = deliveryAddressStatusService.queryOne(result.getOrderNo());
            if (ToolUtil.isNotEmpty(number)) {
                result.setWuLiu(OrderStatus.getOrderInfo(number.getNumber()));
                result.setDeliverTime(number.getCreateTime());
            }
            result.setOrderStatusStr(EnumOrderStatus.getNameByCode(order.getOrderStatus()));
            String userNo = order.getUserNo();
            ShopUser user = userService.queryByUserNo(userNo);
            result.setPhone(user.getPhone());
            OrderGoodsSnapshotParam snapshotParam = JSONObject.parseObject(order.getSnapshot(), OrderGoodsSnapshotParam.class);
            result.setGoodsName(snapshotParam.getGoodsName());
            return BaseResponse.success(result);
        }
        return BaseResponse.error("订单不存在");
    }

    @Transactional(rollbackFor = {Exception.class})
    public synchronized BaseResponse add(GopSaveOrderParams param) {
        ShopUser appUser = userService.queryByPhone(param.getPhone());
        if (ToolUtil.isEmpty(appUser)) {
            return BaseResponse.error("用户不存在!");
        }
        if (ToolUtil.isEmpty(appUser.getParentUserNo())) {
            if (param.getGoodsOrderType().equals(4)) {
                String inviteCode = "";
                if (ToolUtil.isNotEmpty(param.getInviteCode())) {
                    inviteCode = param.getInviteCode();
                }
                String msg = userService.setParentUser1(inviteCode, appUser.getUserNo());
                if (ToolUtil.isNotEmpty(msg)) {
                    return BaseResponse.error(msg);
                } else {
                    userService.checkLv(appUser.getInviteCode(), null, true);
                }
            }
        }
        ShopGoodsSku result = goodsSkuService.getGoodsSkuInfo(param.getBizNo());
        if (ToolUtil.isEmpty(result)) {
            return BaseResponse.error("商品规格不存在!");
        }
        return saveOrUpdate(result, param, appUser.getUserNo());
    }

    /**
     * 创建订单(报单)
     *
     * @param result
     * @param param
     * @return
     */
    public BaseResponse saveOrUpdate(ShopGoodsSku result, GopSaveOrderParams param, String userNo) {
        ShopOrder orderParam = EntityConvertUtils.convertAToB(param, ShopOrder.class);
        try {
            String goodsNo = result.getGoodsNo();
            orderParam.setPhone(param.getConsigneePhone());
            orderParam.setGoodsNo(goodsNo);
            orderParam.setUserNo(userNo);
            orderParam.setOrderNo(StringUtils.getOrderNo());
            if (param.getGoodsOrderType().equals(1)) {
                orderParam.setAmount(result.getPrice().multiply(new BigDecimal(param.getGoodsNumber())));
                if (ToolUtil.isNotEmpty(result.getReturnPoints())) {
                    orderParam.setReturnPoints(result.getReturnPoints());
                }
            } else if (param.getGoodsOrderType().equals(2)) {
                BigDecimal postage = new BigDecimal(RedisUtil.get(RedisKeys.dictionaryKey(EnumDataDictionaryKey.POSTAGE.getKey())).toString());
                orderParam.setAmount(new BigDecimal(0.00).add(postage));
                orderParam.setPostage(postage);
            } else if (param.getGoodsOrderType().equals(3)) {
                orderParam.setAmount(result.getVipPrice().multiply(new BigDecimal(param.getGoodsNumber())));
            } else if (param.getGoodsOrderType().equals(4)) {
                orderParam.setAmount(result.getPrice().multiply(new BigDecimal(param.getGoodsNumber())));
                if (ToolUtil.isNotEmpty(result.getReturnPoints())) {
                    orderParam.setReturnPoints(result.getReturnPoints());
                }
            }
            orderParam.setPayAmount(param.getPrice());
            orderParam.setPayType(0);
            orderParam.setOrderStatus(EnumOrderStatus.PAY_SUCCESS.getCode());
            orderParam.setRefundStatus(EnumShopOrderRefundStatus.REFUND_NOT.getCode());
            orderParam.setOrderType(2);
            orderParam.setPayTime(new Date());
            orderParam.setCreateTime(new Date());
            OrderGoodsSnapshotParam snapshotParam = EntityConvertUtils.convertAToB(result, OrderGoodsSnapshotParam.class);
            ShopGoods goods = goodsService.queryByGoodsNo(goodsNo);
            if (ToolUtil.isNotEmpty(goods)) {
                snapshotParam.setGoodsName(goods.getGoodsName());
                snapshotParam.setGoodsImg(goods.getGoodsImgs());
                snapshotParam.setGoodsCategoryNo(goods.getGoodsCategoryNo());
                snapshotParam.setGoodsOrderType(param.getGoodsOrderType());
                snapshotParam.setVipLevel(goods.getVipLevel());
                orderParam.setGoodsName(snapshotParam.getGoodsName() + " " + snapshotParam.getName());
            } else {
                orderParam.setGoodsName("未定义商品");
            }
            String snapshot = JSON.toJSONString(snapshotParam);
            orderParam.setSnapshot(snapshot);
            orderParam.setParentUserNo("");
            if (goods.getGoodsType() >= 0) {
                String parentUserNo = userService.queryParentUserNo(userNo, goods.getVipLevel());
                orderParam.setParentUserNo(parentUserNo);
            }
            this.saveOrUpdate(orderParam);
            goodsSkuService.updateGoodsSku(param.getBizNo(), param.getGoodsNumber());
            //报单增加积分礼券
            shopOrderPointsService.saveShopOrderPoints(orderParam);
            // 直推
            shopOrderService.addParentFirst(orderParam);
            //变更会员
            if (orderParam.getGoodsOrderType().equals(4)) {
                userService.setVipUser(orderParam.getUserNo(), snapshot);
            }
            return BaseResponse.success();
        } catch (Exception e) {
            log.error("报单失败", e);
            return BaseResponse.error("报单失败");
        }
    }

    public BaseResponse<List<GopGoodsListResult>> getGoodsList(GopGoodsListParams param) {
        Page pageContext = BasePageFactory.defaultPage(param.getPage(), param.getLimit());
        LambdaQueryWrapper<ShopGoods> queryWrapper = new LambdaQueryWrapper<>();
        List<Integer> integerList = EnumGoodsType.getGoodsTypeByGoodsOrderType(param.getGoodsType());
        queryWrapper.in(ShopGoods::getGoodsType, integerList);
        queryWrapper.eq(ShopGoods::getStatus, true);
        queryWrapper.eq(ShopGoods::getIsDeleted, false);
        queryWrapper.and(x -> x.eq(ShopGoods::getHavePreSaleTime, false).or
                (y -> y.eq(ShopGoods::getHavePreSaleTime, true).le(ShopGoods::getPreSaleTime, new Date()))
        );
        queryWrapper.orderByDesc(ShopGoods::getStatus, ShopGoods::getUpdateTime);
        IPage page = goodsService.page(pageContext, queryWrapper);
        List<ShopGoods> shopGoodsList = page.getRecords();
        List<GopGoodsListResult> result = EntityConvertUtils.convertAListToBList(shopGoodsList, GopGoodsListResult.class);
        //所有商品SKU集合
        for (GopGoodsListResult homeShopGoodsResult : result) {
            List<ShopGoodsSku> shopGoodsSkuList = shopGoodsSkuService.listByGoodsNo(homeShopGoodsResult.getGoodsNo());
            homeShopGoodsResult.setGoodsTypeResult(EnumGoodsType.getGoodsTypeByType(homeShopGoodsResult.getGoodsType()));
            String goodsNo = homeShopGoodsResult.getGoodsNo();
            List<ShopGoodsSku> shopGoodsSkus = shopGoodsSkuList.stream().filter(x -> x.getGoodsNo().equals(goodsNo)).collect(Collectors.toList());
            //sku所有库存
            Integer allStock = shopGoodsSkus.stream().mapToInt(ShopGoodsSku::getStock).sum();
            homeShopGoodsResult.setAllStock(allStock);
            homeShopGoodsResult.setSkuList(shopGoodsSkuList);
        }
        page.setRecords(result);
        return BasePageFactory.createPageInfo(page);
    }

    public BaseResponse<List<GopSaleInfoListResult>> saleInfo(GopSaleInfoListParams param) {
        Boolean rootMonth = ToolUtil.isEmpty(param.getType()) ? true : (param.getType().equals("1") ? true :
                (param.getType().equals("2") ? false : true));
        Date startTime;
        Date endTime;
        if (rootMonth) {
            //按月
            String month = param.getMonth();
            if (ToolUtil.isEmpty(month)) {
                startTime = DateUtils.getMonthStart(DateUtils.format(new Date()));
                endTime = DateUtils.getMonthEnd(DateUtils.format(new Date()));
            } else {
                startTime = DateUtils.getMonthStart(month);
                endTime = DateUtils.getMonthEnd(month);
            }
        } else {
            //按季度
            String seasonsStartTime = param.getSeasonsStartTime();
            String seasonsEndTime = param.getSeasonsEndTime();
            if (ToolUtil.isOneEmpty(seasonsStartTime, seasonsEndTime)) {
                startTime = DateUtils.getMonthStart("2022-01");
                endTime = DateUtils.getMonthEnd("2022-03");
            } else {
                startTime = DateUtils.getDateStart(seasonsStartTime);
                endTime = DateUtils.getDateEnd(seasonsEndTime);
            }
        }
        LambdaQueryWrapper<ShopOrder> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.and(x -> x.eq(ShopOrder::getOrderStatus, EnumOrderStatus.PAY_SUCCESS.getCode())
                .or().eq(ShopOrder::getOrderStatus, EnumOrderStatus.DELIVERY_STATUS.getCode())
                .or().eq(ShopOrder::getOrderStatus, EnumOrderStatus.COMPLETE.getCode()));
        queryWrapper.ge(ShopOrder::getPayTime, startTime);
        queryWrapper.le(ShopOrder::getPayTime, endTime);
        List<ShopOrder> shopOrderListAll = list(queryWrapper);
        List<GopSaleInfoListResult> result = new ArrayList<>();
        String tip = "";
        //计算选择时间内总订单
        LambdaQueryWrapper<ShopOrder> queryWrapper2 = new LambdaQueryWrapper<>();
        queryWrapper2.and(x -> x.eq(ShopOrder::getOrderStatus, EnumOrderStatus.PAY_SUCCESS.getCode())
                .or().eq(ShopOrder::getOrderStatus, EnumOrderStatus.DELIVERY_STATUS.getCode())
                .or().eq(ShopOrder::getOrderStatus, EnumOrderStatus.COMPLETE.getCode()));
        queryWrapper2.ge(ShopOrder::getPayTime, startTime);
        queryWrapper2.le(ShopOrder::getPayTime, endTime);
        List<ShopOrder> shopOrderListMonthAll = list(queryWrapper2);
        BigDecimal totalAmount = shopOrderListMonthAll.stream().map(ShopOrder::getPayAmount)
                .reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_DOWN);
        if (rootMonth) {
            List<String> dayInfoResult = DateUtils.getDayList(startTime, endTime);
            for (String dayInfo : dayInfoResult) {
                GopSaleInfoListResult saleInfoListResult = new GopSaleInfoListResult();
                List<ShopOrder> shopOrderList = shopOrderListAll.stream().filter(x -> (
                        x.getPayTime().getTime() <= DateUtils.getDateEnd(dayInfo).getTime()) &&
                        x.getPayTime().getTime() >= DateUtils.getDateStart(dayInfo).getTime())
                        .collect(Collectors.toList());
                saleInfoListResult.setDayInfo(dayInfo);
                saleInfoListResult.setSaleAmount(shopOrderList.stream().map(ShopOrder::getPayAmount).reduce(BigDecimal.ZERO, BigDecimal::add).toString());
                result.add(saleInfoListResult);
            }
            tip = DateUtils.format(startTime, DateUtils.YYYYMM) + " 总销售额：" + totalAmount.toString() + " 元";
        } else {
            List<String> monthInfoResult = DateUtils.getMonthList(startTime, endTime);
            for (String monthInfo : monthInfoResult) {
                GopSaleInfoListResult saleInfoListResult = new GopSaleInfoListResult();
                List<ShopOrder> shopOrderList = shopOrderListAll.stream().filter(x -> (
                        x.getPayTime().getTime() <= DateUtils.getDateEnd(DateUtils.getMonthEnd(monthInfo)).getTime()) &&
                        x.getPayTime().getTime() >= DateUtils.getDateStart(DateUtils.getMonthStart(monthInfo)).getTime())
                        .collect(Collectors.toList());
                saleInfoListResult.setDayInfo(monthInfo);
                saleInfoListResult.setSaleAmount(shopOrderList.stream().map(ShopOrder::getPayAmount).reduce(BigDecimal.ZERO, BigDecimal::add).toString());
                result.add(saleInfoListResult);
            }
            tip = DateUtils.format(startTime, DateUtils.YYYYMM) + " 至 " + DateUtils.format(endTime, DateUtils.YYYYMM)
                    + " 季总销售额：" + totalAmount.toString() + " 元";
        }
        return new BaseResponse(BaseResponse.SUCCESS, "销售统计获取成功", result, tip);
    }

    public BaseResponse<SaleDetailResult> saleDetail(BaseDateQueryParams param) {
        SaleDetailResult result = new SaleDetailResult();
        Page pageContext = BasePageFactory.defaultPage(param.getPage(), param.getLimit());
        LambdaQueryWrapper<ShopOrder> queryWrapper = new LambdaQueryWrapper<>();
        Date time = new Date();
        if (!ToolUtil.isOneEmpty(param.getStartTime(), param.getEndTime())) {
            queryWrapper.apply("UNIX_TIMESTAMP(pay_time) >= UNIX_TIMESTAMP('" + DateUtils.getDateStart(param.getStartTime()) + "')");
            queryWrapper.apply("UNIX_TIMESTAMP(pay_time) <= UNIX_TIMESTAMP('" + DateUtils.getDateEnd(param.getEndTime()) + "')");
        } else {
            queryWrapper.apply("UNIX_TIMESTAMP(pay_time) >= UNIX_TIMESTAMP('" + DateUtils.getDateStart(time) + "')");
            queryWrapper.apply("UNIX_TIMESTAMP(pay_time) <= UNIX_TIMESTAMP('" + DateUtils.getDateEnd(time) + "')");
            param.setStartTime(DateUtils.getDateStartStr(DateUtils.format(time)));
        }
        queryWrapper.and(x -> x.eq(ShopOrder::getOrderStatus, EnumOrderStatus.PAY_SUCCESS.getCode())
                .or(y -> y.eq(ShopOrder::getOrderStatus, EnumOrderStatus.DELIVERY_STATUS.getCode())
                        .or(z -> z.eq(ShopOrder::getOrderStatus, EnumOrderStatus.COMPLETE.getCode()))));
        queryWrapper.eq(ShopOrder::getRefundStatus, EnumShopOrderRefundStatus.REFUND_NOT.getCode());
        IPage page = shopOrderService.page(pageContext, queryWrapper);
        List<ShopOrder> shopOrderList = page.getRecords();
        List<SaleDetailResultList> saleDetailResultLists = EntityConvertUtils.convertAListToBList(shopOrderList, SaleDetailResultList.class);
        //所有商品SKU集合
        for (SaleDetailResultList saleDetailResultList : saleDetailResultLists) {
            OrderGoodsSnapshotParam snapshotParam = JSON.parseObject(saleDetailResultList.getSnapshot(), OrderGoodsSnapshotParam.class);
            saleDetailResultList.setGoodsName(snapshotParam.getGoodsName());
            saleDetailResultList.setPayTimeStr(DateUtils.format(saleDetailResultList.getPayTime(), DateUtils.YYYYMMDDHHMM));
            saleDetailResultList.setSnapshot("");
        }
        result.setList(saleDetailResultLists);
        //累计销售额计算
        queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.apply("UNIX_TIMESTAMP(pay_time) >= UNIX_TIMESTAMP('" + DateUtils.getDateStart(time) + "')");
        queryWrapper.apply("UNIX_TIMESTAMP(pay_time) <= UNIX_TIMESTAMP('" + DateUtils.getDateEnd(time) + "')");
        queryWrapper.eq(ShopOrder::getRefundStatus, EnumShopOrderRefundStatus.REFUND_NOT.getCode());
        List<ShopOrder> shopOrderListA = shopOrderService.list(queryWrapper);
        result.setTodaySaleAmount(
                shopOrderListA.stream().map(ShopOrder::getPayAmount).reduce(BigDecimal.ZERO, BigDecimal::add)
                        .setScale(2, BigDecimal.ROUND_HALF_UP).toString()
        );
        queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.apply("UNIX_TIMESTAMP(pay_time) <= UNIX_TIMESTAMP('" + DateUtils.getDateStart(time) + "')");
        queryWrapper.eq(ShopOrder::getRefundStatus, EnumShopOrderRefundStatus.REFUND_NOT.getCode());
        List<ShopOrder> shopOrderListB = shopOrderService.list(queryWrapper);
        result.setYesterdaySaleAmount(
                shopOrderListB.stream().map(ShopOrder::getPayAmount).reduce(BigDecimal.ZERO, BigDecimal::add)
                        .setScale(2, BigDecimal.ROUND_HALF_UP).toString()
        );
        queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.apply("UNIX_TIMESTAMP(pay_time) <= UNIX_TIMESTAMP('" + DateUtils.getDateStart(param.getStartTime()) + "')");
        queryWrapper.eq(ShopOrder::getRefundStatus, EnumShopOrderRefundStatus.REFUND_NOT.getCode());
        List<ShopOrder> shopOrderListC = shopOrderService.list(queryWrapper);
        result.setQueryTimeSaleAmount(
                shopOrderListC.stream().map(ShopOrder::getPayAmount).reduce(BigDecimal.ZERO, BigDecimal::add)
                        .setScale(2, BigDecimal.ROUND_HALF_UP).toString()
        );
        return BaseResponse.success("统计明细", result, Integer.parseInt(page.getTotal() + ""));
    }
}
